package com.design01_builder.pattern02_factory.factory_method.controller;

import com.design01_builder.pattern02_factory.factory_method.factory.FreeGoodsFactory;
import com.design01_builder.pattern02_factory.factory_method.factory.FreeGoodsFactoryMap;
import com.design01_builder.pattern02_factory.simple_factory.entry.AwardInfo;
import com.design01_builder.pattern02_factory.simple_factory.entry.ResponseResult;
import com.design01_builder.pattern02_factory.simple_factory.service.IFreeGoods;

/**
 * @ClassName DeliverController1
 * @Description TODO
 * @Author zhangjunhao
 * @DATE 2023/9/2 2:05
 */
public class DeliverController1 {


    /**
     * 发放奖品接口
     *
     * @author spikeCong
     * @date 2022/9/7
     **/
    public class DeliverController {
        /**
         * 按照类型的不同发放商品
         */
        public ResponseResult awardToUser(AwardInfo awardInfo) {
            //根据类型获取工厂
            FreeGoodsFactory goodsFactory = FreeGoodsFactoryMap.getParserFactory(awardInfo.getAwardTypes());
            //从工厂中获取对应实例
            IFreeGoods freeGoods = goodsFactory.getInstance();
            System.out.println("=====工厂方法模式========");
            ResponseResult result = freeGoods.sendFreeGoods(awardInfo);
            return result;
        }
    }
}
